package com.byit.controller.quartz;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.byit.constant.DefaultValue;
import com.byit.domain.quartz.JobLog;
import com.byit.enums.PromptInfo;
import com.byit.log.ChannelType;
import com.byit.log.Log;
import com.byit.log.OperatorType;
import com.byit.msg.MessageResult;
import com.byit.service.IJobLogService;
import com.byit.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 调度日志操作处理
 *
 * @author morej
 */
@RestController
@RequestMapping("/api/quartz/jobLog")
public class JobLogController {

	@Autowired
	private IJobLogService jobLogService;

	@Log(title = "定时任务日志", operate = OperatorType.DATA_SELECT, channel = ChannelType.WEB_INTER)
	@GetMapping("/list")
	public Object list(JobLog jobLog,
					   @RequestParam(value = "page", defaultValue = DefaultValue.PAGE_FIRST) int page,
					   @RequestParam(value = "limit", defaultValue = DefaultValue.PAGE_SIZE) int limit) {
		Page<JobLog> pageInfo = new Page<>(page, limit);
		EntityWrapper<JobLog> wrapper = new EntityWrapper<>();
		wrapper.setSqlSelect("*");
		if (StringUtil.isNotNulls(jobLog.getJobName())) {
			wrapper.eq("job_name",jobLog.getJobName());
		}
		if (StringUtil.isNotNulls(jobLog.getMethodName())) {
			wrapper.eq("method_name",jobLog.getMethodName());
		}
		if (StringUtil.isNotNulls(jobLog.getStatus())) {
			wrapper.eq("status",jobLog.getStatus());
		}
        Page<JobLog> jobLogPage = jobLogService.selectPage(pageInfo, wrapper);
		return MessageResult.warpper(PromptInfo.SYS_SECCUSS, jobLogPage);
	}

}
